//
//  LXWelcomeController.swift
//  weibo
//
//  Created by 罗心 on 16/6/27.
//  Copyright © 2016年 罗心. All rights reserved.
//

import UIKit
import SDWebImage

class LXWelcomeController: UIViewController {
    
    override func loadView() {
        view = backgroundImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
        
        headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.view.layoutIfNeeded()
            
            }) { (true) in
                
                UIView.animateWithDuration(0.25, animations: { 
                    
                    self.welcomeLabel.alpha = 1
                    }, completion: { (true) in
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVCNoti, object: "welcome")
                        
                })
        }
        
    }
    
    
    func setupUI() {
        view.addSubview(headImageView)
        view.addSubview(welcomeLabel)
        
        headImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
            make.size.equalTo(CGSizeMake(90, 90))
        }
        welcomeLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
    }
    
    
    //设置背景图片
    private lazy var backgroundImageView:UIImageView = UIImageView(image:UIImage(named:"ad_background"))
    
    //添加圆形头像
    private lazy var headImageView:UIImageView = {
        let image = UIImageView(image:UIImage(named:"avatar_default_big"))
        image.layer.cornerRadius = 45
        image.layer.borderColor = ThemeColor.CGColor
        image.layer.borderWidth = 2.88
        image.layer.masksToBounds = true
        image.sd_setImageWithURL(NSURL(string: (LXUserAccountTools.sharedTools.getUserAccount()?.avatar_large)!), placeholderImage: UIImage(named:"ad_background"))
       return image
    }()
    
    //添加文字标签
    private lazy var welcomeLabel: UILabel = {
        let label = UILabel()
        label.text = "欢迎回来"
        label.font = UIFont.systemFontOfSize(20)        
        label.textAlignment = .Center
        label.textColor = UIColor.darkGrayColor()
        label.alpha = 0
        return label
    }()
    
  
}
